/*
**  File: SLlist.c
**
**  Implements a string list in terms of Glist abstractions.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "General.h"

/* BEGIN_EXTH */
#include "SLlistTypes.h"
/* END_EXTH */

/****************  function prototypes  ****************/

#include "SLlist.h"

/* BEGIN_EXTH */

SLList SLinsertafter( SLPtr data, SLList list, Where where )
{
    SLPtr   new = NEW( SLType, strlen( data ) );
    
    if ( new == NULL )
    {
	fprintf( stderr, "%s\n", "in SLinsertafter: No space" );
	exit( 1 );
    }
    strcpy( new, data );
    return ginsertafter( new, list, where );
}

SLPtr SLcontent( SLList list )
{
    return ( SLPtr ) gcontent( list );
}

SLList SLremove( SLList list )
{
    return gremove( list, (GDelete)( SLremovedata ) );
}

void SLremovedata( SLPtr data )
{
    free( data );
}

void SLprint( SLList list )
{
    gtraverse( list, (GOperation)( SLprintdata ) );
    putchar( '\n' );
}

void SLprintdata( SLPtr data )
{
    printf( "%s ", data );
}

SLList SLfind( SLList list, SLPtr find )
{
    return gfind( list, (GOperation2)( SLfinddata ), find );
}

int SLfinddata( SLPtr data, SLPtr find )
{
    return EQ( data, find );
}
